<script setup>
import {watch} from 'vue'
defineOptions({
  name:"ColorMarks",
  description:"颜色标签，用二进制值表示每一位颜色标签是否被选择"
})
const emit=defineEmits(['change'])
const props=defineProps({
  colors:{
    type:Array,
    default:['#FF625C','#F9A646','#F4CE4A','#6DCC51','#4BB8F3','#D088E1','#A5A5A8']
  },
  mode:{
    type:String,
    default:'1'
  }
})
const model=defineModel({ type: Number, default: 0 })
watch(model,(v)=>{
  emit('change',v);
});
function itemClick(idx){
  model.value^=Math.pow(2,idx)
}
</script>
<template>
  <div v-if="props.mode=='1'" class="marks-input">
    <div v-for="(it,idx) in props.colors" class="item"  :class="{'icon-check':model&Math.pow(2,idx)}" :style="{backgroundColor:it}" @click="itemClick(idx)" >
    </div>
    <div class="item" style="border: 1px solid #CECECE" @click="model=0"></div>
  </div>
  <Tooltip v-else placement="right" theme="white">
    <div class="marks-input mode-2" :style="{width:props.colors.length*12+'px'}">
      <div v-for="(it,idx) in props.colors" v-show="model&Math.pow(2,idx)" class="item" :style="{backgroundColor:it}"  >
      </div>
      <div class="item" style="border: 1px solid #CECECE" v-show="!model"></div>
    </div>
    <template #content>
      <div class="marks-input" >
        <div v-for="(it,idx) in props.colors" class="item"  :class="{'icon-check':model&Math.pow(2,idx)}" :style="{backgroundColor:it}" @click="itemClick(idx)" >
        </div>
        <div class="item" style="border: 1px solid #CECECE" @click="model=0"></div>
      </div>
    </template>
  </Tooltip>

</template>

<style scoped lang="less">
.marks-input{
  display: inline-flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  height: 32px;
  line-height: 32px;
  padding-left: -2px;
}
.item{
  display: inline-block;
  width: 16px;
  height: 15px;
  margin:2px;
  border-radius: 8px;
  overflow: hidden;
  color: white;
  font-weight: bold;
  font-size: 12px;
  text-align: center;
  line-height: 16px;
}
.mode-2{
  height: 32px;
  align-items: center;
  .item{
    margin-left:-8px;
  }
}
</style>
